package com.home.model.entity;

import java.io.Serializable;

import javax.persistence.*;

@Entity
@Table(name = "account")
@NamedNativeQuery(name = "Account.findAccountLogin", query = "select * from account where account.username = :username and account.password = :password", resultClass = Account.class)
public class Account implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String FIND_ACCOUNT_LOGIN = "Account.findAccountLogin";
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id_account")
	private int idAccount;
	@ManyToOne
	@JoinColumn(name = "fk_agent")
	private Agent agent;
	@Column(name = "username")
	private String username;
	@Column(name = "password")
	private String password;
	
	public Account() {
		super();
	}

	public Account(int idAccount, Agent agent, String username, String password) {
		super();
		this.idAccount = idAccount;
		this.agent = agent;
		this.username = username;
		this.password = password;
	}

	public int getIdAccount() {
		return idAccount;
	}

	public void setIdAccount(int idAccount) {
		this.idAccount = idAccount;
	}

	public Agent getAgent() {
		return agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public int hashCode() {
		return getIdAccount();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Account) {
			Account agent = (Account) obj;
			return agent.getIdAccount() == idAccount;
		}

		return false;
	}
}
